package com.example.test.model;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class AsyncDownHeadImageTask implements Runnable  {

	String strImgUrl;
	int position;
	Handler handler;
	public AsyncDownHeadImageTask(Handler handler, int position,String Url)
	{
		this.handler=handler;
		this.position=position;
		strImgUrl=Url;
	}
	
	@Override
	public void run() {
		try {
			URL imgUrl = new URL(strImgUrl);
			InputStream in=(InputStream)imgUrl.getContent();
		    Drawable dwImg =Drawable.createFromStream(in, "img");
		    Message msg = new Message();
		   HashMap<String, Object> map=new HashMap<String, Object>();
		   map.put("position", position);
		   map.put("img",dwImg);
		   msg.what=Constants.MSG_DOWNIMG_SUCCESS;
		   msg.obj=map;
		     handler.sendMessage(msg); // 向Handler发送消息,更新UI
		     Log.v("log","send finish msg");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
	}

	
	
	
	

	
   
}
